package com.dxy.hms.model.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;

import java.time.LocalDateTime;

import com.dxy.hms.model.vo.TreeVo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * <p>
 * 菜单表
 * </p>
 *
 * @author dxy
 * @since 2024-09-24
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("hms_menu")
@ApiModel(value = "Menu对象", description = "菜单表")
public class Menu {

    @ApiModelProperty("菜单编码")
    @TableId(value = "id", type = IdType.INPUT)
    private String id;

    @TableLogic
    private Integer isDeleted;

    @TableField(fill = FieldFill.INSERT)
    private Long createUserId;

    @TableField(fill = FieldFill.INSERT)
    private String createUserName;

    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createTime;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private Long updateUserId;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private String updateUserName;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    private String name;

    @ApiModelProperty("模块")
    private String module;

    @ApiModelProperty("父菜单编码，最顶级默认是-1")
    private String parentId;

    @TableField(exist = false)
    private String parentName;

    // 默认1
    @ApiModelProperty("类型，1-菜单，2-按钮")
    private Integer type;

    // 图标
    private String icon;

    @ApiModelProperty("路由url")
    private String url;

    @ApiModelProperty("排序")
    private Integer sort;

    // 默认1
    @ApiModelProperty("状态，0-禁用，1-启用")
    private Integer status;

    @ApiModelProperty("授权(如：user:create)")
    private String permission;

    public TreeVo toTreeVo() {
        return new TreeVo()
                .setId(this.id)
                .setText(this.name)
                .setVal(this)
                .setParentId(this.parentId)
                .setSort(this.sort)
                .setVisible(true)
                .setHasChildren(false);
    }
}
